#!/usr/bin/env bash
set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
THIRD="$ROOT/third_party"
mkdir -p "$THIRD"

if [ ! -d "$THIRD/lwip" ]; then
  echo "[*] Cloning lwip ..."
  git clone https://git.savannah.nongnu.org/git/lwip.git "$THIRD/lwip"
else
  echo "[=] lwip exists, skipping clone"
fi

if [ ! -d "$THIRD/lwip-contrib" ]; then
  echo "[*] Cloning lwip-contrib ..."
  git clone https://git.savannah.nongnu.org/git/lwip/lwip-contrib.git "$THIRD/lwip-contrib"
else
  echo "[=] lwip-contrib exists, skipping clone"
fi

echo "[✓] Done. Now run:"
echo "    mkdir -p build && cd build"
echo "    cmake -DLWIP_DIR=../third_party/lwip -DLWIP_CONTRIB_DIR=../third_party/lwip-contrib .."
echo "    cmake --build . -j"
